import { createVNode, render, h } from 'vue'

import promptMsg from './promptMsg.vue'

const div = document.createElement('div')
div.setAttribute('class', 'xui-message-container')
document.body.appendChild(div)

const prompt = (message: string, title: string, value: string): Promise<string> =>  {
    return new Promise((resolve, reject) => {
        const msg_node = createVNode(promptMsg, 
            {
                title,
                message,
                value,
                onClose: () => {
                    let timer = setTimeout(()=>{
                    render(null, div)
                    }, 1)
                // clearTimeout(timer)        
                },
                onConfirm: (s: string) => {
                    resolve(s)
                }
            })    
        render(msg_node, div)
    })
}

export default {
    prompt
}